class Itemization < ActiveRecord::Base  
  belongs_to            :approval
  belongs_to            :item
  belongs_to            :item_option
  validates_presence_of :item_option
  validate              :must_belong_to_either_an_item_or_an_approval
  validate              :must_belong_to_only_an_item_or_an_approval
  
  def must_belong_to_either_an_item_or_an_approval
    self.errors.add(:item_option, "Itemization must belong to either an approval or an item") unless self.item or self.approval
  end
  
  def must_belong_to_only_an_item_or_an_approval
    self.errors.add(:item_option, "Itemization must belong to either an approval or an item") if self.item and self.approval
  end
end
